function [f, t]=fr(coefs, nstart, nend, Nt)
% Fourier Reconstruction
% input:
%        coefs: Frouier coefficients;
%        Nt+1: number of samples on time
%        nstart: start index of coefs;
%        nend: start index of coefs;
% output:
%        F: vector -- restructed signal;
% Call: fft
% 
%----------------------------------------
% Principle: 
% Application: Fourier series
% Assertion: nstart - nend < Nt
% Example: 
% See also fft czt


if nargin<=3
    Nt=length(coefs);
    if nargin<=1
        L = length(coefs);
        nstart=-floor(L/2); nend = L + nstart - 1;
    end
end

t = linspace(0, 1, Nt+1);
d = Nt - L;
if d >= 0
    coefs = [coefs, zeros(1, d)];
end
if iscolumn(coefs)
    t=t.';
end
f = ifft(coefs) .* exp(2j*pi*nstart*t(1:end-1)) * Nt;
f(end+1) = f(end);
end